//
//  ImageExamineViewController.m
//  TestDemo
//
//  Created by zhangwenqiao on 2018/12/3.
//  Copyright © 2018年 zhangwenqiao. All rights reserved.
//

#import "ImageExamineViewController.h"
#import "LZImageBrowserMainView.h"
#import "LZImageBrowserManger.h"
#import <SDWebImage.h>
@interface ImageExamineViewController ()
@property (nonatomic, strong) LZImageBrowserManger *imageBrowserManger;
@end

@implementation ImageExamineViewController

+ (instancetype)initWithImageExamineViewController:(NSMutableArray *)iamgeMArray arrtwork:(NSMutableArray *)artworkMArray {
    ImageExamineViewController *imageExamine = [[ImageExamineViewController alloc] init];
    imageExamine.iamgeMArray = iamgeMArray;
    imageExamine.artworkMArray = artworkMArray;
    return imageExamine;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    UIScrollView * scrollView = [[UIScrollView alloc] initWithFrame:Screen_Frame];
    [self.view addSubview:scrollView];
    
    [scrollView setContentSize:CGSizeMake(0, 1200)];
    
    CGFloat W = (Screen_Width-20-10)/3;
//    NSArray * images =  @[@"http://olxnvuztq.bkt.clouddn.com/s01.jpg",@"http://olxnvuztq.bkt.clouddn.com/s02.jpg",@"http://olxnvuztq.bkt.clouddn.com/s03.jpg",@"http://olxnvuztq.bkt.clouddn.com/s04.jpg",@"http://olxnvuztq.bkt.clouddn.com/s05.jpg",@"http://olxnvuztq.bkt.clouddn.com/s06.jpg"];;
    NSArray * images = self.iamgeMArray;
    NSInteger count = (images.count)%3?(images.count/3+1):images.count/3;
    UIView * backView = [[UIView alloc] initWithFrame:CGRectMake(10, 200, Screen_Width-20, count*W + (count-1)*5)];
    [scrollView addSubview:backView];
    backView.backgroundColor = [UIColor grayColor];
    NSMutableArray * originImageViews = [[NSMutableArray alloc] init];
    for (NSInteger i = 0; i < images.count; i++) {
        UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake((i%3)*(W+5), i/3*(W+5), W, W)];
        imageView.userInteractionEnabled = YES;
        imageView.tag = i;
//        [imageView sd_setImageWithURL:[NSURL URLWithString:images[i]]];
        imageView.image = images[i];
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        imageView.clipsToBounds = YES;
        [backView addSubview:imageView];
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTouchAction:)];
        [imageView addGestureRecognizer:tap];
        [originImageViews addObject:imageView];
    }
    
//    NSArray * bigImages = @[@"http://olxnvuztq.bkt.clouddn.com/b01.jpg",@"http://olxnvuztq.bkt.clouddn.com/b02.jpg",@"http://olxnvuztq.bkt.clouddn.com/b03.jpg",@"http://olxnvuztq.bkt.clouddn.com/b04.jpg",@"http://olxnvuztq.bkt.clouddn.com/b05.jpg",@"http://olxnvuztq.bkt.clouddn.com/b06.jpg"];
    
    //初始化 manger
    LZImageBrowserManger *imageBrowserManger = [LZImageBrowserManger imageBrowserMangerWithUrlStr:self.iamgeMArray originImageViews:originImageViews originController:self forceTouch:YES forceTouchActionTitles:@[@"赞", @"评论", @"收藏"] forceTouchActionComplete:^(NSInteger selectIndex, NSString *title) {
        NSLog(@"当前选中%ld--标题%@",(long)selectIndex, title);
    }];
    
    _imageBrowserManger = imageBrowserManger;
}

- (void)imageTouchAction:(UIGestureRecognizer *)ges {
    //点击了的某一个 imageView
    _imageBrowserManger.selectPage = ges.view.tag;
    [_imageBrowserManger showImageBrowser];
}
    
    




/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
